import hotkeys from "hotkeys-js";

export const useHotkeys = (
  keys: string,
  callback: CallableFunction
): (() => void) => {
  hotkeys.filter = () => true;

  hotkeys(keys, (e: Event) => {
    e.preventDefault();
    callback();
    return false;
  });

  return () => {
    hotkeys.unbind(keys);
  };
};

export const removeAllHotkeys = () => {
  hotkeys.unbind();
};
